package com.dj.product.k2faas.entity.datasource;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import com.dj.product.k2faas.common.enums.DBType;
import com.dj.product.k2faas.common.enums.DataStatus;

/**
 * Created by 丁建 on 2025/9/23 09:19
 *
 * @author 丁建
 */
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@Accessors(chain = true)
@Table
@Entity
public class DataSource {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    @Enumerated(EnumType.STRING)
    @Column(length = 36, nullable = false)
    @Comment("数据源类型")
    private DBType type;

    @Column(length = 36, nullable = false, unique = true)
    @Comment("数据源名称")
    private String name;

    @Comment("数据源URL，只在connectionType=JDBC为必填")
    private String url;

    @Column(length = 36, nullable = false)
    @Comment("数据源登录用户名")
    private String username;

    @Column(length = 36)
    @Comment("数据源密码")
    private String password;

    @Comment("连接超时时间（毫秒）")
    private int connectionTimeout = 60000;

    @Comment("最大连接数量")
    private int maxPoolSize = 10;

    @Comment("最小Idle")
    private int minimumIdle = 3;

    @Comment("idle超时时间（毫秒）")
    private int idleTimeout = 30000;

    @Comment("连接最长生命周期（毫秒）")
    private int maxLifetime = 2000000;

    @Comment("自动提交")
    private boolean autoCommit = true;

    @Comment("数据库是否是默认连接")
    private boolean defaultConnection = false;

    @Comment("数据源状态")
    @Enumerated(EnumType.STRING)
    private DataStatus status = DataStatus.NORMAL;

}
